<?php

!defined('ADMIN') && exit('Not allowed to directly view page');
/*
*    发送测试邮件
*/
if($isajax=='1')
{				
	AjaxHead();	
	if(!CheckEmail($test_email))
	{
		echo "测试Email格式不正确！";
		exit();
	}		
	$mailtitle = "{$cfg_webname}--邮件测试";
	$mailbody = '';
	$mailbody .= "您好！这是一封检测邮件服务器设置的测试邮件。\r\n收到此邮件，意味着您的邮件服务器设置正确！您可以进行其他邮件发送的操作了！\r\n";
	$headers = "From: ".$smtp_email."\r\nReply-To: ".$smtp_email;
	if($issmtp == '1' || !isset($issmtp))
	{		
		$mailtype = 'TXT';
		require_once(DEDEINC.'/mail.class.php');
		$smtp = new smtp($smtp_host,$smtp_port,true,$smtp_email,$smtp_pw);
		$smtp->debug = false;
		$sent=$smtp->sendmail($test_email, $smtp_email, $mailtitle, $mailbody, $mailtype);
		if($sent) echo "邮件发送成功";
		else echo "邮件发送失败";
		//echo $test_email."-".$smtp_email.$smtp_port."-".$smtp_pw."-".$smtp_host;
	}
	else
	{
		@mail($test_email, $mailtitle, $mailbody, $headers);
	}
	exit();
}

/*
*    预约邮件参数设置
*/
if(empty($action)||$action=='edit')
{	
	if(empty($step))
	{
		$sql = "select * from `#@__yy_email`";
		$dsql->SetQuery($sql);
		$dsql->Execute();
		while($row=$dsql->GetArray())
		{
			$emailset[$row['key']]=$row['value'];
		}
		include(DEDEADMIN."/templets/yuyue_email.htm");
		exit();
	}
	else if($step=='2')
	{	
		if(!CheckEmail($_POST['smtp_email']))
		{
			ShowMsg('SMTP服务器的用户邮箱： Email格式不正确！', '-1');
			exit();
		}
		foreach($_POST as $k=>$v)
		{
			$dsql->ExecuteNoneQuery("Update `#@__yy_email` set `value`='$v' where `key`='$k' ");
		}
		ShowMsg("成功更改邮件配置！！","?do=yuyue_email");
		exit();		
	}

}
/*
*
*    预约邮件模板设置
*/
else if($action=='template')
{	
	if(empty($step))
	{
		$sql="select * from `#@__yy_templates` ";
		$dsql->SetQuery($sql);
		$dsql->Execute();
		while($row=$dsql->GetArray())
		{
			$templates[$row['id']]=$row;
		}
		if(!isset($id)) $id=1;
		include(DEDEADMIN."/templets/yuyue_email.htm");
		exit();
	}
	else if($step=='2')
	{
		$sql = "update `#@__yy_templates` set  is_html='$is_html' ,content='$content', last_modify=".time()." where id='$id' ";
		if(!$dsql->ExecuteNoneQuery($sql))
		{
			$errinfo .= $sql."\n";
		}
		if(trim($errinfo)  != '' )
		{
			ShowMsg($errinfo,'?do=yuyue_email');
			exit();
		}
		else
		{
			ShowMsg('更新模板成功','?do=yuyue_email&action=template');
			exit();
		}
	}
}


?>
